<?php
namespace Home\Controller;
use Common\Controller\HomeBaseController; 

class ArticleController extends HomeBaseController {
	
	
	public $cates;
	function _initialize() {
		parent::_initialize();
	
	//	print_r(C('URL_ROUTE_RULES'));
	$this->cates=F("Cates");
	$this->assign("cates",$this->cates);
	
	}
	


    public function index(){


    	$catid=I("get.catid");
    	$this->assign("catid",$catid);
    	$cate=D("Cate")->where(array("id"=>$catid))->find();
    	$this->assign("cate",$cate);
    	
    	//print_r($cate);
    	
    	if(!$cate[status]){
    		
    		$this->error("栏目不存在或者未开放使用");
    	}
    	if($cate[redirt]){
    	
    		redirect($cate[url]);
    	}
    	
    	$page_config=array(
    			"rule" => array(
    					"index"=>$cate[url],//这种是表示当前是首页，无需加分页1
    					"list"=>$cate[url]."?p=*",//这种表示分页非首页时启用
    			),
    			"isrule"=>true,
    	
    	);
    	$order_array=I("get.order")?I("get.order"):"top desc,listorder desc,updatetime desc,id desc";
    
    	
    	
    		$s = array ();
    		foreach ( explode ( ",", $catid ) as $k => $v ) {
    			 
    			$s = array_merge ( $s, explode ( ",", $this->cates [$v] [arrchildid] ) );
    		}
    		$map [catid] = array ("in",	$s);
    
    	
    	
    	$count=M("Article")->where($map)->count();
    	$page = $this->page($count, $cate[p_size],'',$page_config);
    	$where[where]=$map;
    	$where[limit]=$page->firstRow;
    	$where[num]= $page->listRows;
    	//$list=M("Article")->field('content',true)->where($map)->limit($page->firstRow . ',' . $page->listRows)->order ( $order_array)->select();
    	$list=D("Article")->get_list($where);
    	$this->assign("Page",$page->show(""));
    	 
    	
    	$this->assign("_list",$list);
    	
    	$this->assign("seo_title",$cate[name]." -- ".C("SITE_NAME"));
    	$this->assign("seo_keywords",$cate[name]);
    	$this->assign("seo_description",$cate[desc]?$cate[desc]:$cate[name]);
    	
    	if($cate[type]==1){
    		//频道
    		$this->display("/".$cate[model]."/".$cate[tpl_cl]);
    	}
    	if($cate[type]==2){
    		 
    		//列表
    		$this->display("/".$cate[model]."/".$cate[tpl_list]);
    	
    	}
    	 
    	
    	 
    	 
    	 
    	
    	 
    	 
    	 
    	
    }
    public function show(){
    	$id=I("get.id");
    	$data=D("Article")->where(array("id"=>$id))->find();
    	//print_r($reult);
    	$cate=F("Cates")[$data[catid]];
    	//print_r($cate);
    	$this->assign("cate",$cate);
    	$this->assign("catid",$cate[id]);
    	$this->assign("_data",$data);
    	
    	
    	$this->assign("seo_title",$data[title]." -- ".C("SITE_NAME"));
    	$this->assign("seo_keywords",$data[tags]?$data[tags]:$data[title]);
    	$this->assign("seo_description",$data[desc]?$data[desc]:$data[name]);
    	
    	
    	$this->display("/".$cate[model]."/".$cate[tpl_show]);
    	
    }
    
    

    

    

}